﻿@{
    Layout = null;
}
<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <title>存货大类</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link href="~/Content/X-admin/css/font.css" rel="stylesheet" />
    <script src="~/Content/X-admin/lib/layui/layui.js"></script>
    <link href="~/Content/X-admin/css/xadmin.css" rel="stylesheet" />
    <script src="~/Content/X-admin/js/jquery.min.js"></script>
    <script src="~/Content/X-admin/js/xadmin.js"></script>
    <script src="~/Content/Scripts/System/systemFrame.js"></script>
    <script type="text/html" id="barDemo">
        @if (ViewData["operate"].ToString().Contains("update"))
        {
            <a title="编辑信息" href="javascript:;" lay-event="icEdit"><i class="layui-icon">&#xe642;</i></a>
            <a title="删除信息" href="javascript:;" lay-event="icDel"><i class="layui-icon">&#xe640;</i></a>
        }
    </script>

</head>
<body>
    <div class="layui-fluid">
        <div class="layui-row layui-col-space15">
            <div class="layui-col-md12">
                <div class="layui-card">
                    <div class="layui-card-body ">
                        <form class="layui-form layui-col-space5" name="qForm" id="qForm">
                            <div class="layui-inline layui-show-xs-block">

                                <input type="text" name="cCode" placeholder="请输入编码" autocomplete="off" class="layui-input" id="cCode">
                            </div>
                            <div class="layui-inline layui-show-xs-block">

                                <input type="text" name="cName" placeholder="请输入名称" autocomplete="off" class="layui-input" id="cName">
                            </div>
                            <div class="layui-inline layui-show-xs-block">
                                <button class="layui-btn" lay-filter="sreach" id="userSearch" type="button" onclick="loadData()"><i class="layui-icon">&#xe615;</i></button>
                            </div>
                        </form>
                    </div>
                    <div class="layui-card-header">
@if (ViewData["operate"].ToString().Contains("sync"))
{
                        <button class="layui-btn" id="userAdd" type="button" onclick="syncData()"><i class="layui-icon">&#xe641;</i>数据同步</button>
}
                        @if (ViewData["operate"].ToString().Contains("update"))
{
    <button class="layui-btn" id="btnUpdate" type="button" onclick="addData()"><i class="layui-icon"></i>添加信息</button>
}
                        <span style="margin-left: 20px; padding: 7px; background-color: #ffd800;font-size:Xx-small">数据停用</span>
                    </div>
                    <div class="layui-card-body layui-table-body layui-table-main" id="layui-table-main">
                        <table class="layui-hide" id="list" lay-filter="list"></table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>

</html>

<script>

    function loadData() {
        layui.use('table', function () {
            var conditon = JSON.stringify(FormToJson("qForm"));
            var table = layui.table;
            table.render({
                elem: '#list'
            , cols: [[ //标题栏
                { field: 'id', title: 'ID', width: 80 }
                 , { field: 'cCode', title: '类别编码', width: 100 }
                 , { field: 'cName', title: '类别名称', width: 130 }
                 , { field: 'statusName', title: '数据状态', width: 110 }
                 , { field: 'isSyncName', title: '同步数据', width: 110 }
                 , { field: 'createtime', title: '创建时间', width: 150 }
                 , { fixed: 'right', title: '操作', width: 100, align: 'center', toolbar: '#barDemo' }
            ]], done: function (res, curr, count) {
                $("[data-field='id']").css('display', 'none');//隐藏列
                $.each(res['data'], function (i, obj) {
                    var status = obj["status"];
                    if (status == "close") {
                        TableRowColor('layui-table-main', i, '#ffd800');
                    }
                });
            }
        //  , height: $(document).height() - $('#list').offset().top - 20
            , url: "../Basis/GetDataList?condition=" + conditon + "&dataType=venClass"
            , skin: 'row' //表格风格
            , even: true
            , page: true //是否显示分页
            , limits: [20, 35, 50]
            , limit: 20 //每页默认显示的数量
            });
            //监听工具条
            table.on('tool(list)', function (obj) {
                var data = obj.data,
                     layEvent = obj.event;
                if (layEvent == 'icEdit') {
                    if (data.isSync == "Y") {
                        layer.msg("同步数据禁止修改！");
                    } else {
                        InfoOpenPage('../Basis/UpdateInventoryClass?dataId=' + data.id, data.cName + "-修改", "65%", "80%");
                    }
                } else {
                    if (data.isSync == "Y") {
                        layer.msg("同步数据禁止删除！");
                    } else {
                        layer.confirm('确定删除此存货大类？', function (index) {
                            $.ajax({
                                url: "../Basis/DelInventoryClass",
                                data: { dataId: data.id },
                                type: 'post',
                                success: function (rsl) {
                                    if (rsl.Result) {
                                        layer.msg('删除成功！');
                                    } else {
                                        layer.msg('删除失败！');
                                    }
                                    loadData()
                                }
                            })
                            layer.close('index')
                        })
                    }
                }

            });

        });
    }
    $(function () {
        //获取列表
        loadData();
    })
    /**
    数据同步方法
    **/
    function syncData() {
        $.ajax({
            url: "../Basis/SyncData?dataType=venClass",
            dataType: "json",
            type: "POST",
            success: function (data) {
                if (data.Result) {
                    layer.msg("同步执行成功");
                    loadData();
                } else {
                    layer.msg(data.Message);
                }
            }
        });
    }
    /**
    数据添加方法
    **/
    function addData() {
        InfoOpenPage('../Basis/UpdateInventoryClass?dataId=0', '新增存货大类', "65%", "80%")
    }

</script>